<!--  -->
<template>
  <div class="login-panel" @keydown.enter="handleClick">
    <h1 class="title">后台管理系统</h1>
    <el-tabs type="border-card" :stretch="true" v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user-solid"></i> 账号登录</span>
        </template>
        <!-- 账号登录插槽 -->
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
        </template>
        <!-- 手机登录插槽 -->
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="account-countrol">
      <el-checkbox v-model="isKeepPassWord">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" size="small" class="loginBtn" @click="handleClick"
      >立即登录</el-button
    >
  </div>
</template>
<script>
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'
import { defineComponent, ref } from 'vue'
export default defineComponent({
  components: {
    LoginAccount,
    LoginPhone
  },
  setup() {
    const currentTab = ref('account') //记录一下当前是使用什么方式登录
    const isKeepPassWord = ref(true)
    const accountRef = ref() //账号登录组件
    const phoneRef = ref() //手机登录组件
    const handleClick = () => {
      //判断一下登录方式
      if (currentTab.value === 'account') {
        console.log('账号登录')
        // 调用组件里面的函数，并且将是否记住密码的参数传递过去
        accountRef.value.loginAction(isKeepPassWord.value) //点击登录按钮时，找到login组件并调用该组件里面的一个方法
      } else {
        phoneRef.value.phoneLogin()
      }
    }
    return {
      isKeepPassWord,
      handleClick,
      currentTab,
      accountRef,
      phoneRef
    }
  }
})
</script>
<style lang="less" scoped>
.login-panel {
  margin-top: -200px;
  width: 320px;
  .title {
    text-align: center;
  }
  .account-countrol {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding: 0 5px;
  }
  .loginBtn {
    width: 70%;
    margin: 10px auto;
    margin-left: 50px;
  }
}
</style>
